package com.hup.utils.commons;

/**
 * @author hugan
 * @date 2019/8/9
 */
public class TimerPicker {

    private static final ThreadLocal<TimerPicker> TP = ThreadLocal.withInitial(TimerPicker::new);

    private long st;
    private long step;

    public TimerPicker() {
        //防止没有markStart,就调用其他方法
        st = System.currentTimeMillis();
    }

    public void markStart0() {
        st = System.currentTimeMillis();
        step = st;
    }

    public static void markStart() {
        TP.get().markStart0();
    }

    public long getTotalTime0() {
        long cur = System.currentTimeMillis();
        return cur - st;
    }
    public static long getTotalTime() {
        return TP.get().getTotalTime0();
    }

    public String getTotal0() {
        long cur = System.currentTimeMillis();
        return DateBuilder.spanCharMs(cur - st);
    }

    public static String getTotal() {
        return TP.get().getTotal0();
    }

    public String getTotal0(String desc) {
        return desc + getTotal0();
    }

    public static String getTotal(String desc) {
        return desc + getTotal();
    }

    public long getStepTime0() {
        long cur = System.currentTimeMillis();
        long res = cur - step;
        step = cur;
        return res;
    }

    public static long getStepTime() {
        return TP.get().getStepTime0();
    }

    public String getStep0() {
        long cur = System.currentTimeMillis();
        String res =  DateBuilder.spanCharMs(cur - step);
        step = cur;
        return res;
    }

    public static String getStep() {
        return TP.get().getStep0();
    }

    public String getStep0(String desc) {
        return desc + getStep0();
    }

    public static String getStep(String desc) {
        return desc + getStep();
    }

}
